<!--
 * @Author: wangming
 * @Date: 2021-04-01 14:02:25
 * @LastEditors: wangming
 * @LastEditTime: 2021-09-17 17:37:02
 * @Description: file content
-->
<template>
  <div>
    <el-form-item label="图类型">
      <el-radio-group v-model="value.__config.mapType" style="width: 100%">
        <el-radio label="mindmap">脑图树</el-radio>
        <el-radio label="compactBox">紧凑树</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="布局方向">
      <el-radio-group v-model="value.__config.direction" style="width: 100%">
        <el-radio label="LR">水平向右</el-radio>
        <!-- <el-radio label="TB">垂直向下</el-radio> -->
        <el-radio label="H">水平对称</el-radio>
        <!-- <el-radio label="V">垂直对称</el-radio> -->
      </el-radio-group>
    </el-form-item>
    <el-form-item label="对称逻辑" v-if="value.__config.direction === 'H'">
      <el-button
        @click="editJSON"
        type="primary"
        icon="el-icon-edit"
        plain
        size="mini"
        >配置</el-button
      >
    </el-form-item>
    <el-form-item label="交互配置" labelWidth="200">
      <el-checkbox-group v-model="value.__config.behavior" class="cl">
        <el-checkbox label="zoom-canvas">缩放画布</el-checkbox>
        <el-checkbox label="drag-canvas">拖拽画布</el-checkbox>
        <el-checkbox label="drag-node">拖拽节点</el-checkbox>
      </el-checkbox-group>
    </el-form-item>
    <el-form-item label="下拉菜单">
      <el-button
        @click="editJSMenu"
        type="primary"
        icon="el-icon-edit"
        plain
        size="mini"
        >配置</el-button
      >
    </el-form-item>
  </div>
</template>

<script>
import basicmixins from "./basicmixins";
import monacoEditor from "./hlTableList/monacoEditor/index.js";
const template = `/**
 * 渲染菜单数据
 * @param {*} node 当前tree的对象
 * @returns string | 'left' or  'right'
 */
function getSide(node) {
  if(node){
    return 'left'
  }else{
    return 'right'
  }
}`;
const menuTemplate = `/**
 * 渲染菜单数据
 * @param {*} node 当前tree的对象
 * @returns [object] | [{ label:string,event:string,icon:string,show:boolean,hide:boolean }]
 * icon 目前只支持element-ui icon
 * hide true 表示隐藏
 * event 函数事件名称
 * label 菜单名称
 */
function getDropMenus(node) {
  return []
}`;
export default {
  mixins: [basicmixins],
  created() {
    !!this.value.__config.behavior ||
      this.$set(this.value.__config, "behavior", []);
  },
  data() {
    return {
      behavior: [],
    };
  },
  methods: {
    editJSMenu() {
      let jsx = this.value.__config.dropMenu || menuTemplate;
      monacoEditor
        .showEdit(decodeURIComponent(jsx), { title: "配置下拉菜单" })
        .then((res) => {
          Object.assign(this.value.__config, {
            dropMenu: encodeURIComponent(res),
          });
        });
    },
    editJSON() {
      let jsx = this.value.__config.sideJson || template;
      monacoEditor
        .showEdit(decodeURIComponent(jsx), { title: "配置功能图逻辑" })
        .then((res) => {
          Object.assign(this.value.__config, {
            sideJson: encodeURIComponent(res),
          });
        });
    },
  },
};
</script>

<style lang="scss" scoped></style>
